import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './components/app/app.component';
import {ProductService} from './service/product/product.service';
import {Product1Component} from './components/component-service/product1/product1.component';
import {Product2Component} from './components/component-service/product2/product2.component';
import {MessageService} from './service/message/message.service';
import {Product3Component} from './components/component-service/product3/product3.component';
import {AnotherProductService} from './service/another-product/another-product.service';
import {BindComponent} from './components/bind/bind.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HomeComponent} from './components/component-service/home/home.component';
import {AppRoutingModule} from './app-routing.module';
import {ResponseComponent} from './components/response/response.component';
import {MultiplePipe} from './pipe/multiple.pipe';
import {OrderComponent} from './components/component-communication/order/order.component';
import {ChildrenComponent} from './components/component-communication/children/children.component';
import {PriceQuoteComponent} from './components/component-communication/price-quote/price-quote.component';
import {LifeComponent} from './components/life-cycle/life/life.component';
import {ChildComponent} from './components/life-cycle/child/child.component';
import {ParentComponent} from './components/life-cycle/parent/parent.component';
import {ViewComponent} from './components/life-cycle/view/view.component';
import {ViewChildComponent} from './components/life-cycle/view-child/view-child.component';
import {ShortcutkeyComponent} from './components/shortcutkey/shortcutkey.component';
import {ContentComponent} from './components/life-cycle/content/content.component';
import {ContentChildComponent} from './components/life-cycle/content-child/content-child.component';
import {FormComponent} from './components/form/form/form.component';
import {ReactiveFormComponent} from './components/form/reactive-form/reactive-form.component';
import {ReactiveRegistComponent} from './components/form/reactive-regist/reactive-regist.component';
import {PhoneDirective} from './directive/phone/phone.directive';
import {PasswordDirective} from './directive/password/password.directive';
import {ComponentComponent} from './components/http/component/component.component';
import {HttpClientModule} from '@angular/common/http';
import {WebSocketService} from './service/webSocket/web-socket.service';
import { WebSocketComponent } from './components/http/web-socket/web-socket.component';
import { HomesComponent } from './components/homes/homes.component';


@NgModule({
  declarations: [
    AppComponent,
    Product1Component,
    Product2Component,
    Product3Component,
    BindComponent,
    HomeComponent,
    ResponseComponent,
    MultiplePipe,
    OrderComponent,
    ChildrenComponent,
    PriceQuoteComponent,
    LifeComponent,
    ChildComponent,
    ParentComponent,
    ViewComponent,
    ViewChildComponent,
    ShortcutkeyComponent,
    ContentComponent,
    ContentChildComponent,
    FormComponent,
    ReactiveFormComponent,
    ReactiveRegistComponent,
    PhoneDirective,
    PasswordDirective,
    ComponentComponent,
    WebSocketComponent,
    HomesComponent
  ],
  imports: [
    BrowserModule,
    FormsModule, /*模板式表单*/
    AppRoutingModule,
    ReactiveFormsModule, /*响应式表单*/
    HttpClientModule
  ],
  /*所有模块可见*/
  providers: [{
    provide: ProductService,
    /*工厂模式，声明的是单列对象*/
    useFactory: (logger: MessageService, appConfigs) => {
      /*let logger = new MessageService();*/
      /*把第三个提供器的值注入isDev*/
      /*let dev = Math.random() > 0.5;*/
      if (appConfigs.isDev) {
        return new ProductService(logger);
      } else {
        return new AnotherProductService(logger);
      }
    },
    /*工厂模式参数设置*/
    deps: [MessageService, 'APP_CONFIGS']
  }, MessageService,
    /*第三个控制提供器,注入的数据是一个明确的值*/
    {
      provide: 'APP_CONFIGS', useValue: {isDev: false, isTest: true}
    }, WebSocketService],
  bootstrap: [AppComponent]
})
export class AppModule {
}
